package com.cn.wanxi.util.servlet;

import com.cn.wanxi.util.model.*;
import com.cn.wanxi.util.service.impl.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/school")//外部访问后台的接口（地址）
public class HomeServletServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        这里就是提供给前端访问页面的地址，并且将数据发送给前端页面
        HeaderService headerService = new HeaderService();
        SchoolContent2Service schoolContent2Service =new SchoolContent2Service();
        SchoolContentService schoolContentService =new SchoolContentService();
        AboutNavService aboutNavService=new AboutNavService();
        BannerService bannerService =new BannerService();
        HttpSession session = req.getSession();
//        页面头部联系方式
        List<ContactModel> contactModels = headerService.getContac();
        session.setAttribute("contancList",contactModels);
//        页面导航
        List<NavModel> navModels = headerService.getNav();
        session.setAttribute("navList",navModels);
//        导航LOGO
        LogoModel logoModel =headerService.getLogo();
        session.setAttribute("logoImg",logoModel);
//        页面头部图片
        List<BannerModel> bannerModel = bannerService.getBannerModel();
        session.setAttribute("bannerModels",bannerModel);

//        页面小导航
        List<AboutNavModel> aboutNavModels =aboutNavService.getaboutNavM();
        session.setAttribute("aboutNavModels",aboutNavModels);
//        页面小标题
        List<CommunalTitle> communalTitles = headerService.getCommunalTitle();
        session.setAttribute("communalTitles",communalTitles);
//        课程介绍
        List<SchoolCurriculumModel> schoolCurriculumModels =schoolContentService.getSchoolCurriculum();
        req.setAttribute("schoolCurriculumModels",schoolCurriculumModels);
//        服务介绍
        List<SchoolServerModel> schoolServerModels = schoolContentService.getSchoolServer();
        req.setAttribute("schoolServerModels",schoolServerModels);
//        关于我们
        List<SchoolAboutModel> schoolAboutModels =schoolContentService.getSchoolAbout();
        req.setAttribute("schoolAboutModels",schoolAboutModels);
//        展示栏小标题
        List<SchoolTitleModel> schoolTitleModels = schoolContent2Service.getSchoolTitleModel();
        req.setAttribute("schoolTitleModels",schoolTitleModels);
//        公司理念
        List<ConpanyIdeaModel> conpanyIdeaModels = schoolContent2Service.getConpanyIdeaModel();
        req.setAttribute("conpanyIdeaModels",conpanyIdeaModels);
//        学校新闻
        List<SchoolNewsModel> schoolNewsModels = schoolContent2Service.getSchoolNewsModel();
        req.setAttribute("schoolNewsModels",schoolNewsModels);
//        联系方式
        List<SchoolContacModel> schoolContacModels =schoolContent2Service.getSchoolContacModel();
        req.setAttribute("schoolContacModels",schoolContacModels);
       gotoSchool(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        super.doPost(req, resp);
        gotoSchool(req,resp);
    }
    private void gotoSchool(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("/jsp/school.jsp").forward(req,resp);
    }
}